package com.xiaoma.mvcconfig;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 每次请求保存相关request信息
 * @author summer 2016年10月8日 下午12:01:41
 */
public class SessionInterceptor extends HandlerInterceptorAdapter{
	
	/**
	 * This implementation always returns {@code true}.
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws Exception {
		SessionHolder.setCurrentHttpServletRequest(request);
		return true;
	}

	/**
	 * This implementation is empty.
	 */
	@Override
	public void postHandle(
            HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
			throws Exception {
		SessionHolder.removeCurrentSession();
	}

	/**
	 * This implementation is empty.
	 */
	@Override
	public void afterCompletion(
            HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
	}

	/**
	 * This implementation is empty.
	 */
	@Override
	public void afterConcurrentHandlingStarted(
            HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
	}
}
